import api from '../index.js';

var home = {};

// 轮播图
home.banner = function(page, limit, areas_id) {
	return new Promise((resolve, reject) => {
		api.get(api.url.Banner, {
				page: page,
				limit: limit,
				areas_id: areas_id
			},
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}

// 访客码
home.passCode = function(data) {
	return new Promise((resolve, reject) => {
		api.post(api.url.CreatePassCode, data,
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}

// 资讯类型
home.infoType = function(page, limit, areas_id) {
	return new Promise((resolve, reject) => {
		api.get(api.url.DocumentType, {
				page: page,
				limit: limit,
				areas_id: areas_id
			},
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}

// 资讯
home.getDocument = function(page, limit, areas_id, type_id) {
	return new Promise((resolve, reject) => {
		api.get(api.url.Documents, {
				page: page,
				limit: limit,
				areas_id: areas_id,
				type_id: type_id
			},
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}

// 资讯详情
home.getDocumentDetail = function(id) {
	return new Promise((resolve, reject) => {
		api.get(api.url.Document, {
				id: id
			},
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}


// 招聘
home.recruitment = function(page, limit, type, work_experience, education, salary_max, salary_min) {
	return new Promise((resolve, reject) => {
		api.get(api.url.PostList, {
				page: page,
				limit: limit,
				type: type,
				work_experience: work_experience,
				education: education,
				salary_max: salary_max,
				salary_min: salary_min
			},
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}

// 租房信息
home.getRentList = function(page, limit, type, house_type, areas_id, min_price, max_price) {
	return new Promise((resolve, reject) => {
		api.get(api.url.MessageIssues, {
				page: page,
				limit: limit,
				type: type,
				house_type: house_type,
				areas_id: areas_id,
				min_price: min_price,
				max_price: max_price
			},
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}

// 租房详情
home.getRentDetail = function(id) {
	return new Promise((resolve, reject) => {
		api.get(api.url.MessageIssue, {
				id: id
			},
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}

// 获取个人招租列表--户主
home.selfSendRentList = function(page, limit, address_id) {
	return new Promise((resolve, reject) => {
		api.get(api.url.UserMessageIssues, {
				page: page,
				limit: limit,
				address_id: address_id
			},
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}

// 删除招租信息
home.delSendRent = function(id) {
	return new Promise((resolve, reject) => {
		api.delete(api.url.DelMessageIssue, {
				id: id
			},
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}

// 商城
// 获取商品列表
home.goodsList = function(page, limit, name, merchant_id, order, type) {
	return new Promise((resolve, reject) => {
		api.get(api.url.ShopGoods, {
				page: page,
				limit: limit,
				name: name,
				merchant_id: merchant_id,
				order: order,
				type: type
			},
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}


module.exports = home;
